define(function(require, exports, module) {
	var template = require("template");
	var Ajax = require("ajax");
	var layer = require("layer");
	var util = require('util');
	var DropDown = require('dropdown');
	require('dropdownCss');
	require('validationJs');
	require('validationRule');
	require('validationCss');
	var set = function(callback) {
		this.init.apply(this, arguments);
	}

	set.prototype = {
		constructor : set,
		options : {},
		init : function(options) {
			var t = this;
			t.options = $.extend({}, t.options, options);
			$("#infoPermission").val($.cookie("roleEnum"));
			// 确定用户权限
//			$("#infoPermission").val("");
			// 切换导航
			t.bindNav();
			//滚动条置顶
			window.scrollTo(0,0);
			if ($.cookie("roleEnum") == "admin_super") {
				$(".account_add").text("新增组织");
				$(".account_add").removeClass("account_admin_add").addClass("account_company_add");
				$("#accountset").addClass('current');
				$(".tipConNav").text("账户管理");
				var accountUrl = localhost+'company/query.do';
				t.loadAccountList(1,10,accountUrl);
			}else{
				$(".tipConNav").text("监测方案配置");
				t.loadMonitorList(1,10,localhost+'information/selectInformationByCompanyId.do');
			}
		},
		bindNav : function() {
			var t = this;
			if ($.cookie("roleEnum") == "admin_super") {
				//accountset
				$(".monitorRight").remove();
				$(".departRight").remove();
				$(".pwdRight").remove();
				$("#accountset").addClass('current');
				$(".tipConNav").text("账户管理");
				$("#accountsetbox").removeClass('hide');
			}else if($.cookie("roleEnum") == "user_simple") {
				//pwdset
				$(".monitorRight").remove();
				$(".accountRight").remove();
				$(".departRight").remove();
				$("#pwdset").addClass('current');
				$(".tipConNav").text("修改密码");
				$("#pwdsetbox").removeClass('hide');
				$("#pwdsetbox").html(template("changePwdFormTemplate"));
				t.controlPwd();
			}else if($.cookie("roleEnum") == "user_depart") {
				$(".departRight").remove();
			}
			
			$("#monitorset").unbind('click').on('click',function() {
				$(".tipConNav").text("监测方案配置");
				if (!$(this).hasClass('current')) {
					$(".cur_toggle").removeClass('current');
					$(this).addClass('current');
				}
				$(".cur_box").addClass('hide');
				$("#monitorsetbox").removeClass('hide');
				$(window).off('scroll');
				t.loadMonitorList(1,10,localhost+'information/selectInformationByCompanyId.do');
			});
			$("#accountset").unbind('click').on('click',function() {
				$(".tipConNav").text("账户管理");
				if (!$(this).hasClass('current')) {
					$(".cur_toggle").removeClass('current');
					$(this).addClass('current');
				}
				$(".cur_box").addClass('hide');
				$("#accountsetbox").removeClass('hide');
				$(window).off('scroll');
				if ($.cookie("roleEnum") == "admin_super") {
					$(".account_add").text("新增组织");
					$(".account_add").removeClass("account_admin_add").addClass("account_company_add");
					var accountUrl = localhost+'company/query.do';
				} else {
					$(".account_add").text("新增账号");
					$(".account_add").removeClass("account_company_add").addClass("account_user_add");
					var accountUrl = localhost+'user/query.do';
				}
				t.loadAccountList(1,10,accountUrl);

			});
			$("#departset").unbind('click').on('click',function() {
				$(".tipConNav").text("部门管理");
				if (!$(this).hasClass('current')) {
					$(".cur_toggle").removeClass('current');
					$(this).addClass('current');
				}
				$(".cur_box").addClass('hide');
				$("#departsetbox").removeClass('hide');
				$(window).off('scroll');
				t.loadDepartmentList(1,10,localhost+'depart/query.do');
			});
			$("#pwdset").unbind('click').on('click', function() {
				$(".tipConNav").text("修改密码");
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				if (!$(this).hasClass('current')) {
					$(".cur_toggle").removeClass('current');
					$(this).addClass('current');
				}
				$(".cur_box").addClass('hide');
				$("#pwdsetbox").removeClass('hide');
				$("#pwdsetbox").html(template("changePwdFormTemplate"));
				t.controlPwd();
			});
		},
		// 监测方案配置
		loadMonitorList : function(pageIndex, pageSize, url) {
			var t=this;
        	Ajax.ajax({
				url : url,
				data : {pageIndex : pageIndex,pageSize : pageSize},
				beforeSend : function() {
					$('#monitor_table>tbody').html(template("loadingDom"));
				},
				success : function(data) {
					if (data.returnCode == 10000) {
                        if(data.returnData && data.returnData.length > 0) {
                        	var totalRecords =  data.totalRecords;
                            $("#Pagination").pagination({
                                recordCount: totalRecords || 1,        //总记录数data.totalRecords
                                thisPageIndex:pageIndex,
                                pageSize: 10,           //一页记录数
                                onPageChange: function (pageIndex,keyword) {
                                    Ajax.ajax({
										url: url,
                                        data: {pageIndex : pageIndex,pageSize : pageSize},
                                        beforeSend:function(){
                        					$('#monitor_table>tbody').html(template("loadingDom"));
                                        },
                                        success : function(data) { 
                                            loadDataList(data.returnData);      //传获取的数据
                                            t.bindMonitorEvent();
                                        }
                                    });
                                }
                            });
                            $('#monitor_table>tbody').html("");
                            loadDataList(data.returnData);      //传获取的数据
                            $('.pagination').css('visibility','visible');
                            $('.page_footer').css('visibility','visible');
                        } else {
							$('#monitor_table>tbody').html(template("noDataDom"));
                            $('.pagination').css('visibility','hidden');
                            $('.page_footer').css('visibility','hidden');
                        } 
						t.bindMonitorEvent();
					} 
				}
			});
        	
        	function loadDataList(dataList){
        		$('#monitor_table>tbody').html("");
				var tHead = '', tList = '';
				tHead = "<tr class='th'><th>方案名称</th><th colspan='2'>操作</th><th colspan='2'>状态</th></tr>";
				for (var i = 0; i < dataList.length; i++) {
					var item = dataList[i], icon = '',iconText='',colors='';
					// 表格
					tList += '<tr class="tb" data-ifmid="' + item.ifmId + '">';
					tList += '<td>' + item.ifmName + '</td>';
					tList += '<td><a href="javascript:;" ';
					tList += isNull(item.createTime,'data-createTime=');
					tList += isNull(item.ifmFilterpattern,'data-ifmFilterpattern=');
					tList += isNull(item.ifmGetbbsname,'data-ifmGetbbsname=');
					tList += isNull(item.ifmGetbloggerid,'data-ifmGetbloggerid=');
					tList += isNull(item.ifmGetchannel,'data-ifmGetchannel=');
					tList += isNull(item.ifmGetkeyword,'data-ifmGetkeyword=');
					tList += isNull(item.ifmGetwechatid,'data-ifmGetwechatid=');
					tList += isNull(item.ifmId,'data-ifmId=');
					tList += isNull(item.ifmIsdelete,'data-ifmIsdelete=');
					tList += isNull(item.ifmIssensitivity,'data-ifmIssensitivity=');
					tList += isNull(item.ifmMatepattern,'data-ifmMatepattern=');
					tList += isNull(item.ifmName,'data-ifmName=');
					tList += isNull(item.ifmNotbbsname,'data-ifmNotbbsname=');
					tList += isNull(item.ifmNotbloggerid,'data-ifmNotbloggerid=');
					tList += isNull(item.ifmNotchannel,'data-ifmNotchannel=');
					tList += isNull(item.ifmNote,'data-ifmNote=');
					tList += isNull(item.ifmNotkeyword,'data-ifmNotkeyword=');
					tList += isNull(item.ifmNotwechatid,'data-ifmNotwechatid=');
					tList += isNull(item.ifmPushed,'data-ifmPushed=');
					tList += isNull(item.ifmType,'data-ifmType=');
					tList += isNull(item.updateTime,'data-updateTime=');								
					
					tList += ' class="monitor_edit edit_color">编辑</a></td>';
					tList += '<td><a href="javascript:;" class="monitor_del del_reset_color">删除</a></td>';

					if (item.ifmIsdelete == 0) {
						icon = '&#xeef4;';
						iconText = '关闭';
						colors = 'colors_close';
					}else{
						icon = '&#xeef5;';
						iconText = '开启';
						colors = 'colors_open';
					}
					tList += '<td><span class="iconfont col doInfoPermission" data-ifmIsdelete = "' + item.ifmIsdelete + '">'+icon+'</span></td>';
					tList += '<td><span class="'+colors+'">'+iconText+'</span></td>';
					tList += '</tr>';
				}
				
				//如果属性值为空，那么此元素就不添加该属性
				function isNull(isText,data){
					if(isText||isText=='0'){
						var tL = data + "'"+isText+"'";
					}else{
						tL = '';
					}
					return tL;
				}

				$('#monitor_table>tbody').append(tHead + tList);
        	}
		},

		// 账号管理
		loadAccountList : function(pageIndex,pageSize, url) {
			var t=this;
        	Ajax.ajax({
				url : url,
				data : {
					pageIndex : pageIndex
				},
				beforeSend : function() {
					$('#account_table>tbody').html(template("loadingDom"));
				},
				success : function(data) {
					if (data.returnCode == 10000) {
                        if(data.returnData && data.returnData.length > 0) {
                            $("#Pagination").pagination({
                                recordCount: data.totalRecords || 1,        //总记录数
                                thisPageIndex:pageIndex,
                                pageSize: 10,           //一页记录数
                                onPageChange: function (pageIndex,keyword) {
                                    Ajax.ajax({
										url: url,
                                        data: {pageIndex : pageIndex,pageSize : pageSize},
                                        beforeSend:function(){
                        					$('#account_table>tbody').html(template("loadingDom"));
                                        },
                                        success : function(data) {
                                            loadDataList(data.returnData);      //传获取的数据
                                            t.bindAccountEvent();
                                        }
                                    });
                                }
                            });
                            $('#account_table>tbody').html("");
                            loadDataList(data.returnData);      //传获取的数据
                            $('.pagination').css('visibility','visible');
                            $('.page_footer').css('visibility','visible');
                        } else {
                        	$('#account_table>tbody').html(template("noDataDom"));
                            $('.pagination').css('visibility','hidden');
                            $('.page_footer').css('visibility','hidden');
                        } 
                        t.bindAccountEvent();
					}
				}
			});
        	
        	function loadDataList(dataList){
        		$('#account_table>tbody').html("");
				var tHead = '', tList = '';
				if ($.cookie("roleEnum") == "admin_super") {
					tHead = "<tr class='th'><th>组织</th><th>创建时间</th><th>详情</th><th colspan='2'>操作</th></tr>";
					for (var i = 0; i < dataList.length; i++) {
						var item = dataList[i];
						// 表格
						tList += '<tr class="tb" data-companyId="' + item.companyId + '">';
						tList += '<td>' + item.companyName + '</td>';
						tList += '<td>' + item.createTime + '</td>';
						tList += '<td><a href="javascript:;" class="account_company_check" data-companyName="'+ item.companyName +'" data-companyId="'+ item.companyId +'">查看</a></td>';
						tList += '<td><a href="javascript:;" class="account_admin_add" data-companyId="'+ item.companyId +'">新增管理员 </a></td>';
						tList += '<td><a href="javascript:;" class="account_company_del">删除</a></td>';
					}
				} else {
					tHead += "<tr class='th'><th>账号</th><th>使用人</th><th>部门</th><th>职位</th><th>权限</th>";
					if($.cookie("roleEnum") !== "user_depart"){
						tHead += "<th>密码重置</th>";
					}
					tHead += "<th colspan='2'>操作</th></tr>";
					for (var i = 0; i < dataList.length; i++) {
						var item = dataList[i];
						// 表格
						tList += '<tr class="tAccount" data-userid="' + item.userId + '">';
						tList += '<td>' + item.userAccount + '</td>';
						tList += '<td>' + item.userName + '</td>';
						tList += '<td>' + item.depart.departName + '</td>';
						tList += '<td>' + item.userJob + '</td>';
						if(item.maxRole.roleGrade==200){
							var roles = 1;
						}else if(item.maxRole.roleGrade==150){
							var roles = 2;
						}else if(item.maxRole.roleGrade==100){
							var roles = 3;
						}
						tList += '<td>' + roles + '</td>';
						if($.cookie("roleEnum") !== "user_depart"){
							tList += '<td><a href="javascript:;" class="account_user_reset del_reset_color" data-userid="'+ item.userId +'">重置</a></td>';
						}
						tList += '<td><a href="javascript:;" data-userName="'+ item.userName +'" data-userId="'+ item.userId +'" data-userAccount="'+ item.userAccount +'" data-departId="'+ item.depart.departId +'" data-departName="'+ item.depart.departName +'" data-userJob="'+ item.userJob + '" data-roleGrade="'+ item.maxRole.roleGrade + '" data-userPhone="'+ item.userPhone +'" class="account_user_edit edit_color">编辑</a></td>';
						tList += '<td><a href="javascript:;" class="account_user_del del_reset_color">删除</a></td>';
						tList += '</tr>';
					}
				}
				tList += '</tr>';
				$('#account_table>tbody').append(tHead + tList);
        	}
		},

		// 部门管理
		loadDepartmentList : function(pageIndex, pageSize,url) {
			var t=this;
        	Ajax.ajax({
				url : url,
				data : {
					pageIndex : pageIndex
				},
				beforeSend : function() {
					$('#department_table>tbody').html(template("loadingDom"));
				},
				success : function(data) {
					if (data.returnCode == 10000) {
						if (data.returnData && data.returnData.length > 0) {
                            $("#Pagination").pagination({
                                recordCount: data.totalRecords || 1,        //总记录数
                                thisPageIndex:pageIndex,
                                pageSize: 10,           //一页记录数
                                onPageChange: function (pageIndex,keyword) {
                                    Ajax.ajax({
										url: url,
                                        data: {pageIndex : pageIndex,pageSize : pageSize},
                                        beforeSend:function(){
                        					$('#account_table>tbody').html(template("loadingDom"));
                                        },
                                        success : function(data) {
                                            loadDataList(data.returnData);      //传获取的数据
                                            t.bindDepartmentEvent();
                                        }
                                    });
                                }
                            });
                            $('#department_table>tbody').html("");
                            loadDataList(data.returnData);      //传获取的数据
                            $('.pagination').css('visibility','visible');
                            $('.page_footer').css('visibility','visible');
							
						} else {
							$('#department_table>tbody').html(template("noDataDom"));
                            $('.pagination').css('visibility','hidden');
                            $('.page_footer').css('visibility','hidden');
						}
						t.bindDepartmentEvent();
					} 
				}
			});
        	
        	function loadDataList(dataList){
        		$('#department_table>tbody').html("");
				var tHead = '', tList = '';
				tHead = "<tr class='th'><th>部门名称</th><th>人数</th><th>详情</th><th>操作</th></tr>";
				for (var i = 0; i < dataList.length; i++) {
					var item = dataList[i];
					// 表格
					tList += '<tr class="tDepart" data-departId="' + item.departId + '">';
					tList += '<td>' + item.departName + '</td>';
					tList += '<td>' + item.userNum + '</td>';
					tList += '<td><a href="javascript:;" data-departName="' + item.departName +'" class="department_check check_color">查看</td><td><a href="javascript:;" class="department_del">删除</td>';
					tList += '</tr>';
				}

				$('#department_table>tbody').append(tHead + tList);
//				util.CutOff(); // 截断过长文字
        	}
		},

		bindMonitorEvent : function() {
			var t = this;
			// 监测方案新增
			$("#monitor_add").unbind('click').on('click', function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html(template("monitorForm"));
				t.controlMonitorForm();
			});
			// 监测方案编辑
			$(".monitor_edit").on("click",	function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html('');
				$("#twobox").html(template("monitorForm"));
				
				$("#isSensitive").val($(this).attr("data-ifmissensitivity"));
				
				$("#ifmId").val($(this).attr("data-ifmId")||'');
				$("#ifmName").val($(this).attr("data-ifmName")||'');
				if (($(this).attr("data-ifmName")||'') == "None") {
					$("#ifmGetKeyword").val("");
				} else {
					$("#ifmGetKeyword").val($(this).attr("data-ifmGetkeyword")||'');
				}
				if (($(this).attr("data-ifmNotkeyword")||'') !== 'None') {
					$("#ifmNotKeyword").val($(this).attr("data-ifmNotkeyword"));
				} else {
					$("#ifmNotKeyword").val('');
				}
				$("#title").html('编辑监测方案');
				// 来源
				if (($(this).attr("data-ifmGetbbsname")||'') == 'All') {
					$("#luntan").html('&#xeeeb;').addClass('checked');
				}
				if (($(this).attr("data-ifmGetbloggerid")||'') == 'All') {
					$("#weibo").html('&#xeeeb;').addClass('checked');
				}
				if (($(this).attr("data-ifmGetchannel")||'') == 'All') {
					$("#news").html('&#xeeeb;').addClass('checked');
				}
				
				if (($(this).attr("data-ifmGetwechatid")||'') == 'All') {
					$("#weixin").html('&#xeeeb;').addClass('checked');
				}
				
				// 是否敏感
				if (($(this).attr("data-ifmIssensitivity")||'') == 0) {
					$(".sc .iconfont[data-type=0]").html('&#xeeeb;').addClass('checked');
					$(".sc .iconfont[data-type=1]").html('&#xeeea;').removeClass('checked');
				}else{
					$(".sc .iconfont[data-type=1]").html('&#xeeeb;').addClass('checked');
					$(".sc .iconfont[data-type=0]").html('&#xeeea;').removeClass('checked');
				}
				
				// 匹配关键词
				if (($(this).attr("data-ifmMatepattern")||'') == 'title|content') {
					$("#onetitle").html('&#xeeeb;').addClass('checked');
					$("#onecontent").html('&#xeeeb;').addClass('checked');
				}else if (($(this).attr("data-ifmMatepattern")||'') == 'title') {
					$("#onetitle").html('&#xeeeb;').addClass('checked');
				}else if (($(this).attr("data-ifmMatepattern")||'') == 'content') {
					$("#onecontent").html('&#xeeeb;').addClass('checked');
				}
				// 过滤关键词
				if (($(this).attr("data-ifmFilterpattern")||'') == 'title|content') {
					$("#twotitle").html('&#xeeeb;').addClass('checked');
					$("#twocontent").html('&#xeeeb;').addClass('checked');
				}else if (($(this).attr("data-ifmFilterpattern")||'') == 'title') {
					$("#twotitle").html('&#xeeeb;').addClass('checked');
				}else if (($(this).attr("data-ifmFilterpattern")||'') == 'content') {
					$("#twocontent").html('&#xeeeb;').addClass('checked');
				}
				t.controlMonitorForm();
				
			});
			
			// 监测方案删除
			$(".monitor_del").unbind('click').on("click", function() {
				var param = {
					ifmId : $(this).parents('tr').attr('data-ifmid')
				};
				layer.confirm('确定要删除此方案吗？', {
					btn : [ '取消', '确定' ],
					btn2 : function() {
						Ajax.ajax({
							url : localhost + "information/deleteByPrimaryKey.do",
							data : param,
							success : function(data) {
								if (data.returnCode == 10000) {
									$(window).off('scroll');
									if($(".monitor_table .tb").length>1){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.loadMonitorList(parseInt($('.navi font').text()),10,localhost+'information/selectInformationByCompanyId.do');
										});
									}else if($("#prevBtn").css("display")=="inline"){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.loadMonitorList(parseInt($('.navi font').text())-1,10,localhost+'information/selectInformationByCompanyId.do');
										});										
									}else{
										layer.msg(data.returnMessage,{time:1000},function(){$('#monitor_table>tbody').html(template("noDataDom"));});
									}
								}
							}
						});
					}
				});
			});
			
			//监测方案开启关闭
			$(".doInfoPermission").unbind('click').on('click',function(){
				var isOpen='',ifmIsdelete='';
				if($(this).attr('data-ifmIsdelete')==0){
					isOpen = '开启';
					ifmIsdelete = 1;
				}else{
					var isOpen = '关闭';
					ifmIsdelete = 0;
				}
				var param = {
					ifmId : $(this).parents('tr').attr('data-ifmid'),
					ifmIsdelete : ifmIsdelete	
				};
				layer.confirm('确定要'+ isOpen +'方案吗？', {
					btn : [ '取消', '确定' ],
					btn2 : function() {
						Ajax.ajax({
							url : localhost + "information/updateInformationType.do",
							data : param,
							success : function(data) {
								if (data.returnCode == 10000) {
									$(window).off('scroll');
//									t.loadMonitorList(1,10,localhost+'information/selectInformationByCompanyId.do');
									layer.msg(data.returnMessage,{time:1000},function(){$("#goBtn").trigger("click");});
								}
							}
						});
					}
				});
			});
		},
		saveMonitor : function() {
			var t = this;
			$("#setMonitorForm").validationEngine({
				focusFirstField : true,
				scroll : true,
				showOneMessage : false,
				promptPosition : "topRight:10,10",
				addPromptClass : "formError-style-layout",
				validationEventTrigger : "blur",
				maxErrorsPerField : "1",
			});

			// 验证关键词的特殊字符
			var strReg = "^[\u4e00-\u9fa5a-zA-Z0-9+|()\\s\\\\]+$";
			var re = new RegExp(strReg);
			if ($.trim($("#ifmGetKeyword").val()) != '' && !re.test($.trim($("#ifmGetKeyword").val()))) {
				layer.msg("匹配关键词含有非法字符");
				return false;
			} else if ($.trim($("#ifmNotKeyword").val()) != '' && !re.test($.trim($("#ifmNotKeyword").val()))) {
				layer.msg("过滤关键词含有非法字符");
				return false;
			} else if ($("#nametip").html() != '') {
				return false;
			}
			var isSuccess = $('#setMonitorForm').validationEngine('validate');
			var ifmId = $("#ifmId").val();
			if ($('#news').hasClass('checked')) {
				var getChannel = 'All';
				var notChannel = 'None';
			} else {
				var getChannel = 'None';
				var notChannel = 'All';
			}
			if ($('#weixin').hasClass('checked')) {
				var getWechatId = 'All';
				var notWechatId = 'None';
			} else {
				var getWechatId = 'None';
				var notWechatId = 'All';
			}
			if ($('#weibo').hasClass('checked')) {
				var getBloggerId = 'All';
				var notBloggerId = 'None';
			} else {
				var getBloggerId = 'None';
				var notBloggerId = 'All';
			}
			if ($('#luntan').hasClass('checked')) {
				var getBbsName = 'All';
				var notBbsName = 'None';
			} else {
				var getBbsName = 'None';
				var notBbsName = 'All';
			}
			if ($('#onetitle').hasClass('checked') && !$('#onecontent').hasClass('checked')) {
				var ifmMatePattern = 'title';
			} else if (!$('#onetitle').hasClass('checked') && $('#onecontent').hasClass('checked')) {
				var ifmMatePattern = 'content';
			} else if ($('#onetitle').hasClass('checked') && $('#onecontent').hasClass('checked')) {
				var ifmMatePattern = 'title|content';
			}
			if ($('#twotitle').hasClass('checked') && !$('#twocontent').hasClass('checked')) {
				var ifmFilterPattern = 'title';
			} else if (!$('#twotitle').hasClass('checked') && $('#twocontent').hasClass('checked')) {
				var ifmFilterPattern = 'content';
			} else if ($('#twotitle').hasClass('checked') && $('#twocontent').hasClass('checked')) {
				var ifmFilterPattern = 'title|content';
			}
			if (($("#ifmNotKeyword").val() == '')
					&& ($("#onetitle").hasClass("checked") || $("#onecontent") .hasClass("checked"))
					&& ($("#news").hasClass("checked") || $("#weixin").hasClass("checked")
					|| $("#weibo").hasClass("checked") || $("#luntan") .hasClass("checked"))) {
				var sourceBool = true;
			} else if (($("#ifmNotKeyword").val() != '')
					&& ($("#twotitle").hasClass("checked") || $("#twocontent").hasClass("checked"))
					&& ($("#onetitle").hasClass("checked") || $("#onecontent").hasClass("checked"))
					&& ($("#news").hasClass("checked") || $("#weixin").hasClass("checked")
					|| $("#weibo").hasClass("checked") || $("#luntan").hasClass("checked"))) {
				var sourceBool = true;
			} else if (!$("#onetitle").hasClass("checked") && !$("#onecontent").hasClass("checked")) {
				var sourceBool = false;
				layer.msg("请选择匹配关键词是匹配标题还是匹配正文");
			} else if (($("#ifmNotKeyword").val() != '')
					&& (!$("#twotitle").hasClass("checked") && !$("#twocontent").hasClass("checked"))) {
				var sourceBool = false;
				layer.msg("请选择过滤关键词是匹配标题还是匹配正文");
			} else if (!$("#news").hasClass("checked")
					&& !$("#weixin").hasClass("checked")
					&& !$("#weibo").hasClass("checked")
					&& !$("#luntan").hasClass("checked")) {
				var sourceBool = false;
				layer.msg("请至少选择一个来源");
			}
			if (isSuccess == true && sourceBool == true) {
				if (ifmId == '') {// 新增保存
					var dataJson = {
						type : 1,
						ifmName : $.trim($("#ifmName").val()),
						ifmGetkeyword : $.trim($("#ifmGetKeyword").val()),
						ifmNotkeyword : $.trim($("#ifmNotKeyword").val()),
						ifmGetbbsname : getBbsName,
						ifmGetbloggerid : getBloggerId,
						ifmGetchannel : getChannel,
						ifmGetwechatid : getWechatId,
						ifmNotbbsname : notBbsName,
						ifmNotbloggerid : notBloggerId,
						ifmNotchannel : notChannel,
						ifmNotwechatid : notWechatId,
						ifmMatepattern : ifmMatePattern,
						ifmFilterpattern : ifmFilterPattern,
						ifmIssensitivity: $("#isSensitive").val()||0,
						ifmIsdelete : 0
					};
					Ajax.ajax({
						url : localhost + "information/insertOrUpdate.do",
						data : dataJson,
						success : function(data) {
							if(data.returnCode==10000){
								layer.msg(data.returnMessage);
								$("#onebox").removeClass('hide');
								$("#twobox").addClass('hide');
								t.loadMonitorList(1,10,localhost+'information/selectInformationByCompanyId.do');
							}
						}
					});
				} else {// 编辑保存
					var dataJson = {
						type : 2,
						ifmId : ifmId,
						ifmName : $("#ifmName").val(),
						ifmGetkeyword : $("#ifmGetKeyword").val(),
						ifmNotkeyword : $("#ifmNotKeyword").val(),
						ifmGetbbsname : getBbsName,
						ifmGetbloggerid : getBloggerId,
						ifmGetchannel : getChannel,
						ifmGetwechatid : getWechatId,
						ifmNotbbsname : notBbsName,
						ifmNotbloggerid : notBloggerId,
						ifmNotchannel : notChannel,
						ifmNotwechatid : notWechatId,
						ifmMatepattern : ifmMatePattern,
						ifmFilterpattern : ifmFilterPattern,
						ifmIsdelete : 1,
						ifmIssensitivity: $("#isSensitive").val()
						
					};
					Ajax.ajax({
						url : localhost + "information/insertOrUpdate.do",
						data : dataJson,
						success : function(data) {
							if(data.returnCode==10000){
								layer.msg(data.returnMessage);
								$("#onebox").removeClass('hide');
								$("#twobox").addClass('hide');
	                            $('.pagination').css('visibility','visible');
	                            $('.page_footer').css('visibility','visible');
								layer.msg(data.returnMessage,{time:1000},function(){
									t.loadMonitorList(parseInt($('.navi font').text()),10,localhost+'information/selectInformationByCompanyId.do');
								});
							}
						}
					});
				}
			}
		},

		controlMonitorForm : function() {
			var t = this;
			// 单选框控制
			$(".sc .iconfont").unbind('click').on('click',function() {
				$(this).parent().children('.iconfont').html('&#xeeeb;').addClass('checked');
				$("#isSensitive").val($(this).attr("data-type"));
				$(this).parent().siblings().children('.iconfont').html('&#xeeea;').removeClass('checked');
			});

			// 多选框控制
			$(".mc .iconfont").unbind('click').on('click', function() {
				if ($(this).hasClass('checked')) {
					$(this).html('&#xeeea;').removeClass('checked');
				} else {
					$(this).html('&#xeeeb;').addClass('checked');
				}
			});

			// 保存方案
			$("#monitorSave").unbind('click').on('click', function() {
				t.saveMonitor();
			});
			// 取消
			$("#monitorCancel").unbind('click').on('click', function() {
				$(window).off('scroll');
				$("#twobox").addClass('hide');
				$("#onebox").removeClass('hide');
				t.loadMonitorList(parseInt($('.navi font').text()),10,localhost+'information/selectInformationByCompanyId.do');
			});

			// 监测方案重名验证
			// $("#ifmName").on('blur',function(){
			// var nameValue=$.trim($(this).val());
			// var infoId=$("#ifmId").val();
			// Ajax.ajax({
			// url: localhost+"/iformation/selectIsReName",
			// data:{ifmName:nameValue,infoId:infoId},
			// success: function (data) {
			// if(data.returnData==1){
			// $("#nametip").html('方案名重复');
			// }else{
			// $("#nametip").html('');
			// }
			// },
			// });
			// });
		},
		controlPwd : function() {
			var t = this;
			// 保存用户
			$("#doPwdSave").unbind('click').on('click', function() {
				t.savePwd();
			});
			// 取消
			$("#doPwdCancel").unbind('click').on('click', function() {
				if($.cookie("roleEnum")=="user_simple"){
					$("#pwd1").val('');
					$("#modifyPassword").val('');
					$("#pwd2").val('');
				}else{
					$("#pwdset").trigger('click');
				}
				
			});
		},
		
//		swichActive : function(){
//			$(".cur_box").addClass('hide');
//			$("#pwdset").removeClass('current');
//			$("#monitorset").addClass('current');
//			$("#monitorsetbox").removeClass('hide');
//		},

		savePwd : function() {
			var t = this;
			var pwd1 = $("#pwd1").val();
			var modifyPassword = $("#modifyPassword").val();
			var pwd2 = $("#pwd2").val();
			if(modifyPassword!==pwd2){
				layer.msg("两次输入密码不一致，请重新输入！");
				return false;
			}
			var dataJson = {
				pwd1 : pwd1,
				pwd2 : pwd2
			};
			$("#changePwdForm").validationEngine({
				focusFirstField : true,
				scroll : true,
				showOneMessage : false,
				promptPosition : "topRight:10,10",
				addPromptClass : "formError-style-layout",
				validationEventTrigger : "blur",
				maxErrorsPerField : "1",
			});
			if ($('#changePwdForm').validationEngine('validate')) {
				Ajax.ajax({
					url : localhost + "user/modifyPwd.do",
					data : dataJson,
					success : function(data) {
						if (data.returnCode == 10000) {
							layer.msg("密码修改成功，正跳转登录页 ...",{time:2000},function(){
								window.location.href = localhost + "/views/index.jsp#!index/login";
							});
						}
					}
				});
			}
		},

		bindAccountEvent : function() {
			var t = this;
			// 超级管理员新增组织
			$(".account_company_add").unbind('click').on('click', function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html(template("companyForm"));
				t.controlAccountForm();
			});
			// 新增管理员
			$(".account_admin_add").unbind('click').on('click', function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				var companyId = $(this).attr("data-companyId");
				var companyName = $(this).parents('tr').children().eq(0).text();
				$("#twobox").html(template("adminForm"));
				$("#companyName").val(companyName).addClass('color_hui');
				$("#userAccount").val('');
				$("#userPwd").val('');
				$("#hide_companyId").val(companyId);
				t.controlAccountForm();
			});
			// 用户新增账号
			$(".account_user_add").unbind('click').on('click', function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html(template("userForm"));
				if ($.cookie("roleEnum") == "user_com") {
					//去除3级权限分配
					$("#right_select #levelThree").remove();
				}else if ($.cookie("roleEnum") == "user_depart") {
					//部门不可选
					$("#department_select").remove();
					$(".switchRight").parent().find(".dot").remove();
					var html ="<input class='ui-text color_hui' type='text' readonly value='"+ $.cookie('departName') +"'/>"
					$(".switchRight").append(html);
					
					//去除2、3级权限分配
					$("#right_select #levelTwo").remove();
					$("#right_select #levelThree").remove();
				}
				t.controlAccountForm();
				
			});
			
			// 用户重置密码
			$(".account_user_reset").unbind('click').on('click', function() {
        		var userId = $(this).attr("data-userid");
        		var params = {
        			userId: userId
        		}
    			Ajax.ajax({
    				url: localhost + 'user/resetPwd.do',
    				data: params,
    				success: function(data) {
    					if(data.returnCode == 10000){
    						layer.msg(data.returnMessage,{time: 2000},function(){});
    					}
    				}
    			});
				
			});			
			
			// 用户编辑账号
			$(".account_user_edit").on("click",	function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html('');
				var hideUserId = $(this).attr('data-userId');
				var hideDepartId = $(this).attr('data-departId');
			
				var userAccount = $(this).attr("data-userAccount");
				var userName = $(this).attr("data-userName");
				var userPhone = $(this).attr("data-userPhone");
				var departId = $(this).attr("data-departId");
				var departName = $(this).attr("data-departName");
				var userJob = $(this).attr("data-userJob");
				var roleGrade = $(this).attr("data-roleGrade");
				if(roleGrade==100){
					var rightLevel = 3;
				}else if(roleGrade==150){
					var rightLevel = 2;
				}else if(roleGrade==200){
					var rightLevel = 1;
				}
				
				$("#twobox").html(template("userForm"));
				$("#userAccount").parent().siblings().find(".dot").remove();
				$("#userAccount").attr("readonly","readonly");
				$("#userAccount").addClass("color_hui");
				if ($.cookie("roleEnum") == "user_com") {
					//去除3级权限分配
					$("#right_select #levelThree").remove();
				}else if ($.cookie("roleEnum") == "user_depart") {
					//部门不可选
					$("#department_select").remove();
					$(".switchRight").parent().find(".dot").remove();
					var html ="<input class='ui-text color_hui' type='text' readonly value='"+ $.cookie('departName') +"'/>"
					$(".switchRight").append(html);					
					//去除2、3级权限分配
					$("#right_select #levelTwo").remove();
					$("#right_select #levelThree").remove();
				}
				$("#userAccount").val(userAccount);
				$("#userName").val(userName);
				$("#userPhone").val(userPhone);
				$("#userJob").val(userJob);
				$("#rightLevel").text(rightLevel);
				$("#departName").text(departName);
				$("#hide_userId").val(hideUserId);
				$("#departName").attr("data-departid",hideDepartId);
				$("#hide_departId").val(hideDepartId);
				t.controlAccountForm();
				
			});
			
			// 超级管理员查看组织
			$(".account_company_check").unbind('click').on('click', function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html('');
				
				var companyId = $(this).attr('data-companyid');
				var companyName = $(this).attr('data-companyName');
				t.queryCompanyAjax(companyId,companyName);
				t.controlAccountForm();
			});
			
			//超级管理员删除组织
			$(".account_company_del").unbind('click').on('click',function(){
				var param = {
					companyId : $(this).parents('tr').attr('data-companyid')
				};
				layer.confirm('确定要删除该组织吗？', {
					btn : [ '取消', '确定' ],
					btn2 : function() {
						Ajax.ajax({
							url : localhost + "company/delete.do",
							data : param,
							success : function(data) {
								if (data.returnCode == 10000) {
									$(window).off('scroll');
									if($("#account_table .tb").length>1){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.doAccountRefresh(parseInt($('.navi font').text()));
										});
									}else if($("#prevBtn").css("display")=="inline"){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.doAccountRefresh(parseInt($('.navi font').text())-1);
										});										
									}else{
										layer.msg(data.returnMessage,{time:1000},function(){$('#account_table>tbody').html(template("noDataDom"));});
									}
								}
							}
						});
					}
				});
			});
			
			//管理员删除用户
			$(".account_user_del").unbind('click').on('click',function(){
				var param = {
					userId : $(this).parents('tr').attr('data-userid')
				};
				layer.confirm('确定要删除该用户吗？', {
					btn : [ '取消', '确定' ],
					btn2 : function() {
						Ajax.ajax({
							url : localhost + "user/delete.do",
							data : param,
							success : function(data) {
								if (data.returnCode == 10000) {
									$(window).off('scroll');
									if($("#account_table .tAccount").length>1){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.doAccountRefresh(parseInt($('.navi font').text()));
										});
									}else if($("#prevBtn").css("display")=="inline"){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.doAccountRefresh(parseInt($('.navi font').text())-1);
										});										
									}else{
										layer.msg(data.returnMessage,{time:1000},function(){$('#account_table>tbody').html(template("noDataDom"));});
									}
								}
							}
						});
					}
				});
			});
		},
		
		queryCompanyAjax: function(companyId,companyName){
			Ajax.ajax({
				url : localhost + 'user/admin/query.do',
				data : {
					companyId : companyId,
					pageIndex: 1,
					pageSize:10
				},
				type : 'post',
				success : function(data) {
					if (data.returnCode == 10000) {
						var tHead = '',tList = '',tFoot = '';
						tHead += '<div class="companyCheck"><div class="wrap clearfix"><div class="name">组织名称:</div><div class="value">';
						tHead += '<input class="ui-text color_hui" type="text" readonly value="'+ companyName +'"></div></div>';
						if (data.returnData && data.returnData.length > 0) {
							var dataList = data.returnData;
							for (var i = 0; i < dataList.length; i++) {
								var item = dataList[i];
								tList += '<div class="wrap clearfix"><div class="name">管理员账号'+ parseInt(i+1) +':</div><div class="value">';
								tList += '<input class="ui-text color_hui" type="text" readonly value="'+ item.userAccount +'"/></div><div class="delBtnBox"><input type="submit" data-companyId="'+ companyId +'" data-companyName="'+ companyName +'" data-userId="'+ item.userId +'" class="ui-btn adminDel" name="btn" value="删除"/></div></div>';
							}
						}else{
							tList += '<div class="wrap clearfix"><div class="noInfo">暂无该组织管理员信息！</div></div>';
						}
						tFoot += '<div class="wrap clearfix"><div class="btns"><div class="ui-btn ui-btn-cancel" id="accountCheckCancel">关闭</div></div></div></div>';
						$('#twobox').html(tHead + tList + tFoot);
					}
				}
			});
		},

		controlAccountForm : function() {
			var t = this;
			// 保存
			$("#account_company_save").unbind('click').on('click', function() {
				t.doCompanyAccount();
			});
			$("#account_user_save").unbind('click').on('click', function() {
				t.doUserAccount();
			});
			$("#account_admin_save").unbind('click').on('click', function() {
				t.doAdminAccount();
			});
			
			// 取消
			$("#account_company_cancel,#account_user_cancel").unbind('click').on('click',function() {
				t.doAccountRefresh(parseInt($('.navi font').text()));
			});
			
			$(document).unbind('click').on('click','#accountCheckCancel,.adminDel', function(e) {//阻止冒泡事件
				if(e.target.id=='accountCheckCancel'){
					t.doAccountRefresh(parseInt($('.navi font').text()));
				}else{
					var companyId = $(this).attr("data-companyId");
					var companyName= $(this).attr("data-companyName");
					var param = {
						userId : $(this).attr('data-userId')
					};
					layer.confirm('确定要删除此管理员账号吗？', {
						btn : [ '取消', '确定' ],
						btn2 : function() {
							Ajax.ajax({
								url : localhost + "user/delete.do",
								data : param,
								success : function(data) {
									if (data.returnCode == 10000) {
										$(window).off('scroll');
										t.queryCompanyAjax(companyId,companyName);
									}
								}
							});
						}
					});
				}
			});
			
			var dt = new DropDown($('#department_select')); //选择部门
			var rt = new DropDown($('#right_select')); //选择权限
			
			$("#department_select").one('click',function(){
	        	Ajax.ajax({
	        		url: localhost + 'depart/query.do',
	                success: function (data) {
	                	$("#dropdown").html('');
	                	if(data.returnCode==10000){
		                   if(data.returnData.length > 0){
		                	   var item=data.returnData;
		                	   for(var i=0;i<item.length;i++){
		                		   $("#dropdown").append(template("userDepartLi",item[i]));
		                	   }
		                	   t.bindDepartLiEvent();
		                   }else{
		                	   $("#dropdown").html("<li>暂无部门选项</li>");
		                   }
	                	}
	                },
	            });
				
			});
			
			$(document).click(function() {
				// all dropdowns
				$('.wrapper-dropdown').removeClass('active');
			});
		},
		
		bindDepartLiEvent: function(){
        	var t=this;
        	$("#dropdown li").unbind("click").on("click",function(){
        		var departId = $(this).attr("data-departid");
        		var departName = $(this).attr("data-departname");
        		$("#departName").text(departName).attr('data-departid',departId);
        		$("#hide_departId").val(departId);
        	});
		},

		doCompanyAccount : function() {
			var t = this;
			var companyId = $("#hide_companyId").val();
			var companyName = $("#companyName").val();
			var userAccount = $("#userAccount").val() || null;
			var userPwd = $("#userPwd").val() || null;
			var confirmPwd = $("#confirmPwd").val() || null;
			var dataJson = {
				companyId: companyId,
				companyName : companyName,
				userAccount : userAccount,
				userPwd : userPwd,
				confirmPwd : confirmPwd
			};
			$("#setAccountForm").validationEngine({
				focusFirstField : true,
				scroll : true,
				showOneMessage : false,
				promptPosition : "topRight:10,10",
				addPromptClass : "formError-style-layout",
				validationEventTrigger : "blur",
				maxErrorsPerField : "1",
			});
			var isSuccess = $('#setAccountForm').validationEngine('validate');
			if (isSuccess == true) {
				Ajax.ajax({
					url : localhost + "company/add.do",
					data : dataJson,
					success : function(data) {
						if (data.returnCode == 10000) {
							t.doAccountRefresh(1);
							layer.msg(data.returnMessage,{time:1000},function(){});
						}
					}
				});
			}
		},
		
		//账号列表刷新
		doAccountRefresh: function(curPage){
			var t = this;
			$(window).off('scroll');
			$("#twobox").addClass('hide');
			$("#onebox").removeClass('hide');
			if ($.cookie("roleEnum") == "admin_super") {
				$(".icon_add").text("新增组织");
				var accountUrl = localhost+'company/query.do';
			} else {
				$(".icon_add").text("新增账号");
				var accountUrl = localhost+'user/query.do';
			}
			t.loadAccountList(curPage,10, accountUrl);
		},
		
		doUserAccount : function() {
			var t = this,rightLevel='';
			var userAccount = $("#userAccount").val();
			var userName = $("#userName").val();
			var userPhone = $("#userPhone").val();
			var userJob = $("#userJob").val();
			if($("#rightLevel").text()=='1'){
				rightLevel =200;
			}else if($("#rightLevel").text()=='2'){
				rightLevel =150;
			}else if($("#rightLevel").text()=='3'){
				rightLevel =100;
			}
			var userId = $("#hide_userId").val();
			var departId = $("#departName").attr("data-departid")||$("#hide_departId").val();
			var dataJson = {
				userId: userId,
				userAccount: userAccount,
				userName : userName,
				userPhone : userPhone,
				userJob: userJob,
				level: rightLevel,
				departId: departId
			};
			$("#setAccountForm").validationEngine({
				focusFirstField : true,
				scroll : true,
				showOneMessage : false,
				promptPosition : "topRight:10,10",
				addPromptClass : "formError-style-layout",
				validationEventTrigger : "blur",
				maxErrorsPerField : "1",
			});
			var isSuccess = $('#setAccountForm').validationEngine('validate');
			if (isSuccess == true) {
				if(userId){
					var url = "user/update.do";
				}else {
					var url = "user/add.do";
				}
				Ajax.ajax({
					url : localhost + url,
					data : dataJson,
					success : function(data) {
						if (data.returnCode == 10000) {
							if(userId){
								layer.msg(data.returnMessage,{time:2000},function(){
									t.doAccountRefresh(parseInt($('.navi font').text()));
								});
							}else{
								layer.msg(data.returnMessage,{time:2000},function(){
									t.doAccountRefresh(1);
								});
							}
						}
					}
				});
			}
		},
		
		doAdminAccount : function() {
			var t = this,rightLevel='';
			var companyId = $("#hide_companyId").val();
			var userAccount = $("#userAccount").val();
			var userPwd = $("#userPwd").val();
			var confirmPwd = $("#confirmPwd").val();
			var dataJson = {
				companyId:companyId,
				userAccount:userAccount,
				userName:userAccount,
				userPwd: userPwd
			};
			$("#setAccountForm").validationEngine({
				focusFirstField : true,
				scroll : true,
				showOneMessage : false,
				promptPosition : "topRight:10,10",
				addPromptClass : "formError-style-layout",
				validationEventTrigger : "blur",
				maxErrorsPerField : "1",
			});
			var isSuccess = $('#setAccountForm').validationEngine('validate');
			if(userPwd!==confirmPwd){
				layer.msg("两次输入密码不一致，请重新输入！");
				return false;
			}
			if (isSuccess == true) {
				Ajax.ajax({
					url : localhost + 'user/admin/add.do',
					data : dataJson,
					success : function(data) {
						if (data.returnCode == 10000) {
							layer.msg(data.returnMessage,{time:2000},function(){
								t.doAccountRefresh(parseInt($('.navi font').text()));
							});
						}
					}
				});
			}
		},
		
		bindDepartmentEvent: function(){
			var t= this;
			//管理员新增部门
			$("#department_add").unbind('click').on('click',function(){
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html(template("departmentForm"));
				t.controlDepartmentForm();
			});
			
			// 管理员查看部门
			$(".department_check").unbind('click').on('click', function() {
                $('.pagination').css('visibility','hidden');
                $('.page_footer').css('visibility','hidden');
				$("#onebox").addClass('hide');
				$("#twobox").removeClass('hide');
				$("#twobox").html('');
				
				var departId = $(this).parents('tr').attr('data-departid');
				var departName = $(this).attr('data-departName');
				Ajax.ajax({
					url : localhost+'depart/queryUsers.do',
					data : {
						departId : departId,
						pageIndex: 1,
						pageSize:100000
					},
					type : 'post',
					success : function(data) {
						if (data.returnCode == 10000) {
							var tHead = '',tList = '',tFoot = '';
							if (data.returnData && data.returnData.length > 0) {
								var dataList = data.returnData;
								for (var i = 0; i < dataList.length; i++) {
									var item = dataList[i];
									tList += '<div class="wrap clearfix"><div class="name">部门员工'+ parseInt(i+1) +':</div><div class="value">';
									tList += '<input class="ui-text color_hui" type="text" readonly value="'+ item.userName +'"/></div></div>';
								}
							} else{
								tList += '<div class="wrap clearfix"><div class="noInfo">暂无该部门员工信息！</div></div>';
							}
							tHead += '<div class="wrapbox clearfix"><form class="form validationEngineContainer"><div class="wrap clearfix"><div class="name">部门名称:</div><div class="value">';
							tHead += '<input class="ui-text color_hui" type="text" readonly value="'+ departName +'"></div></div>';

							tFoot = '<div class="wrap clearfix"><div class="btns"><div class="ui-btn ui-btn-cancel" id="departmentCheckCancel">关闭</div></div></div></form></div>';
							$('#twobox').html(tHead + tList + tFoot);
						} 
					}
				});
				t.controlDepartmentForm();
			});
			
			$(".department_del").unbind('click').on('click',function(){
				var param = {
					departId : $(this).parents('tr').attr('data-departid')
				};
				layer.confirm('确定要删除此部门吗？', {
					btn : [ '取消', '确定' ],
					btn2 : function() {
						Ajax.ajax({
							url : localhost + "depart/delete.do",
							data : param,
							success : function(data) {
								if (data.returnCode == 10000) {
									$(window).off('scroll');
									if($("#department_table .tDepart").length>1){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.loadDepartmentList(parseInt($('.navi font').text()),10, localhost+'depart/query.do');
										});
									}else if($("#prevBtn").css("display")=="inline"){
										layer.msg(data.returnMessage,{time:1000},function(){
											t.loadDepartmentList(parseInt($('.navi font').text())-1,10, localhost+'depart/query.do');
										});										
									}else{
										layer.msg(data.returnMessage,{time:1000},function(){$('#department_table>tbody').html(template("noDataDom"));});
									}
								}
							}
						});
					}
				});
			});
		},
		
		controlDepartmentForm : function() {
			var t = this;
			// 保存
			$("#departmentSave").unbind('click').on('click', function() {
				t.doDepartment();
			});
			// 取消
			$("#departmentCancel").unbind('click').on('click',function() {
				$(window).off('scroll');
				$("#twobox").addClass('hide');
				$("#onebox").removeClass('hide');
				t.loadDepartmentList(1,10, localhost+'depart/query.do')
			});	
			// 部门查看关闭
			$(document).unbind('click').on('click','#departmentCheckCancel',function() {
				$(window).off('scroll');
				$("#twobox").addClass('hide');
				$("#onebox").removeClass('hide');
				t.loadDepartmentList(parseInt($('.navi font').text()),10, localhost+'depart/query.do');
			});
		},
		
		doDepartment : function() {
			var t = this;
			var departmentName = $("#departmentName").val();
			var dataJson = {
				departName : departmentName
			};
			$("#setDepartmentForm").validationEngine({
				focusFirstField : true,
				scroll : true,
				showOneMessage : false,
				promptPosition : "topRight:10,10",
				addPromptClass : "formError-style-layout",
				validationEventTrigger : "blur",
				maxErrorsPerField : "1",
			});
			var isSuccess = $('#setDepartmentForm').validationEngine('validate');
			if (isSuccess == true) {
				Ajax.ajax({
					url : localhost + "depart/add.do",
					data : dataJson,
					success : function(data) {
						if (data.returnCode == '10000') {
							$(window).off('scroll');
							$("#twobox").addClass('hide');
							$("#onebox").removeClass('hide');
							t.loadDepartmentList(1,10, localhost+'depart/query.do');
							layer.msg(data.returnMessage,{time:1000},function(){});
						}
					}
				});
			}
		}	

	};
	module.exports = set;
});
